package com.zat.mes.andrmes.dofun.work.adapter

import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.DayPlanProduceBeanItem
import com.zat.mes.andrmes.utils.SpannableStrUtil
import kotlinx.android.synthetic.main.item_item_proc_day_produce_plan.view.*

/**
 * @author zy
 * @date :2020-02-25 16:16
 * @description:做工adapter
 */
class DayProducePlanAdapter(layoutResId: Int) :
    BaseQuickAdapter<DayPlanProduceBeanItem, BaseViewHolder>(layoutResId) {


    override fun convert(helper: BaseViewHolder, item: DayPlanProduceBeanItem) {

        helper.setText(R.id.tvNameDayPlayItem, item?.styleName)
            .setText(R.id.tvDateDayPlayItem, item?.planDayDate)
        var styleNo = context.getString(R.string.text_style) + " " + item?.styleNo
        var color = context.getString(R.string.text_color) + " " + item?.color
        var machineNo = context.getString(R.string.text_mac_no) + " " + item?.machineno
        var quantity = context.getString(R.string.text_amount) + " " + item?.sengemntNumber
        var size = context.getString(R.string.text_size) + " " + item?.size
        val textColor = ContextCompat.getColor(context, R.color.color_text_grey)
        if (!TextUtils.isEmpty(item?.machinename)) {
            var machineName = context.getString(R.string.text_mac_name) + " " + item?.machinename
            helper.setText(
                R.id.tvMachineNameDayPlayItem,
                SpannableStrUtil.getColorSpannable(machineName, 4, machineName.length, textColor)
            )
        } else {
            var machineName = context.getString(R.string.text_mac_name) + " "
        }
        helper.setText(
            R.id.tvStyleNoDayPlayItem,
            SpannableStrUtil.getColorSpannable(styleNo, 3, styleNo.length, textColor)
        )
        helper.setText(
            R.id.tvColorDayPlayItem,
            SpannableStrUtil.getColorSpannable(color, 3, color.length, textColor)
        )
//        helper.setText(
//            R.id.tvMachineNoPlayItem,
//            SpannableStrUtil.getColorSpannable(machineNo, 5, machineNo.length, textColor)
//        )
        helper.setText(
            R.id.tvQuantityDayPlayItem,
            SpannableStrUtil.getColorSpannable(quantity, 3, quantity.length, textColor)
        )
        helper.setText(
            R.id.tvSizeDayPlayItem,
            SpannableStrUtil.getColorSpannable(size, 3, size.length, textColor)
        )

        val ivHideShow = helper.getView<ImageView>(R.id.ivDayPlayShowHide)
        val llPro = helper.getView<LinearLayout>(R.id.llProcDayPlayItem)
        //for add view
        if (item?.orderCraftprocessVersionList !== null) {
            llPro.removeAllViews()
            for (orderCraftprocess in item?.orderCraftprocessVersionList) {
                val inflate = LayoutInflater.from(context)
                    .inflate(R.layout.item_item_proc_day_produce_plan, null)
                inflate.tvProcName.text = orderCraftprocess.procName
                inflate.tvProcType.visibility = View.GONE
                inflate.btnMore.visibility = View.GONE
                if (!TextUtils.isEmpty(orderCraftprocess.baseWage)) {
                    inflate.tvJcgj.text =
                        context.getString(R.string.text_base_wage) + " " + orderCraftprocess.baseWage
                }else{
                    inflate.tvJcgj.text =
                        context.getString(R.string.text_base_wage)
                }
                if (!TextUtils.isEmpty(orderCraftprocess.selfWage)) {
                    inflate.tvCngj.text =
                        context.getString(R.string.text_self_wage) + " " + orderCraftprocess.selfWage
                }else{
                    inflate.tvCngj.text =
                        context.getString(R.string.text_self_wage)
                }
                if (!TextUtils.isEmpty(orderCraftprocess.standardValue)) {
                    inflate.tvBzms.text =
                        context.getString(R.string.text_stand_value) + " " + orderCraftprocess.standardValue
                }else{
                    inflate.tvBzms.text =
                        context.getString(R.string.text_stand_value)
                }
                if (!TextUtils.isEmpty(orderCraftprocess.standardTime)) {
                    inflate.tvBzmz.text =
                        context.getString(R.string.text_stand_time) + " " + orderCraftprocess.standardTime
                }else{
                    inflate.tvBzmz.text =
                        context.getString(R.string.text_stand_time)
                }
                if (!TextUtils.isEmpty(orderCraftprocess.ieccoefficient)) {
                    inflate.tvIE.text =
                        context.getString(R.string.text_ie) + " " + orderCraftprocess.ieccoefficient
                }else{
                    inflate.tvIE.text =
                        context.getString(R.string.text_ie)
                }
                llPro.addView(inflate)
            }
        }

        if (item?.show!!) {
            ivHideShow.setImageResource(R.mipmap.icon_shengchanjihua_heqi)
            llPro.visibility = View.VISIBLE
        } else {
            ivHideShow.setImageResource(R.mipmap.icon_shengchanjihua_zhankai)
            llPro.visibility = View.GONE
        }
        helper.getView<LinearLayout>(R.id.llBtnDayPlayShowHide).setOnClickListener {
            //展开收起
            if (item?.show!!) {
                item?.show = false
            } else {
                item?.show = true
            }
            notifyDataSetChanged()
        }
    }
}

